#include "StdAfx.h"
#include "xkImgAnalyBit16.h"

xkImgAnalyBit16::xkImgAnalyBit16(void)
{
	
}

xkImgAnalyBit16::~xkImgAnalyBit16(void)
{
}

int xkImgAnalyBit16::Initialize()
{
	

	return 0;
}
//standard iamge
int xkImgAnalyBit16::LoadStdFile(char *pFileName)
{
	return 0;
}
//
int xkImgAnalyBit16::SetStdImgBuffer(zkImgBitInfo *pImgInfo)
{
	if( NULL == pImgInfo || NULL == pImgInfo->pImageHeader )
	{
		return -1;
	}

	zkImg16BitInfo *pBitInfo = (zkImg16BitInfo *)pImgInfo->pImageHeader;

	m_xStdOrgImg.nBitPerSample = pBitInfo->nBitPerSample;
	m_xStdOrgImg.nSapPerPixel  = pBitInfo->nSapPerPixel;
	m_xStdOrgImg.nWidth        = pBitInfo->nWidth;
	m_xStdOrgImg.nHeight       = pBitInfo->nHeight;
	m_xStdOrgImg.bAutoDelete   = FALSE;

	/////
	unsigned long lSize = pBitInfo->nWidth * pBitInfo->nHeight * sizeof(WORD);
	if( !m_xStdOrgBuffer.Allocate( lSize ) )
	{
		return -1;
	}

	WORD *pwImgData = (WORD*)m_xStdOrgBuffer.pBuffer;
	memcpy(pwImgData,pBitInfo->pwImageData,lSize);
	/////
	m_xStdOrgImg.pwImageData = pwImgData;


	m_xStdBitInfo.dwImgDefine  = eXKImage_Define_Img16;
	m_xStdBitInfo.bAutoDelete  = FALSE;
	m_xStdBitInfo.pImageHeader = &m_xStdOrgImg;
	m_xStdBitInfo.pImageData   = pwImgData;
     
	m_xStdAnalyPro.SetImgBuffer(pImgInfo);

	return 0;
}
//
int xkImgAnalyBit16::StdImgOperate(DWORD dwAnalyType,void *pVoid)
{
	int nRet = DD_ERR_FAILURE;

	do 
	{
		switch (dwAnalyType)
		{
		case ImgAnaly_GradsSharp:
			{
				nRet = 0;
				//m_xStdAnalyPro.Edge();
				long kernel[]={-1,-1,-1,-1,9,-1,-1,-1,-1};
				m_xStdAnalyPro.Filter(kernel,3,0,0);
			}
			break;
		case ImgAnaly_EdgeSharp:
			{
				nRet = 0;
				//long kernel[]={-1,-1,-1,-1,8,-1,-1,-1,-1};
				//m_xStdAnalyPro.Filter(kernel,3,-1,255);
				long kernel[]={-2,-4,-4,-4,-2,-4,0,8,0,-4,-4,-8,43,8,-4,-4,0,8,0,-4,-2,-4,-4,-4,-2};
				m_xStdAnalyPro.Filter(kernel,5,0,0);
			}
			break;
		case ImgAnaly_MaskSharp:
			{
				nRet = DD_ERR_SUCCESS;
				long kernel[]={-1,-1,-1,-1,16,-1,-1,-1,-1};
				m_xStdAnalyPro.Filter(kernel,3,8,0);
			}
			break;
		case ImgAnaly_Smooth:
			{
				nRet = 0;
				long kernel[]={1,1,1,1,8,1,1,1,1};
				m_xStdAnalyPro.Filter(kernel,3,16,0);
			}
			break;
		case ImgAnaly_Emboss:
			{
				if( NULL != pVoid )
				{
					nRet = 0;
					int *pnData = (int*)(pVoid);
					long kernel[]={0,0,-1,0,0,0,1,0,0};
					m_xStdAnalyPro.Filter(kernel,3,0,*pnData);
				}	
			}
			break;
		case ImgAnaly_HighStrain:
			{
				nRet = 0;
				long kernel[]={-1,-1,-1,-1,15,-1,-1,-1,-1};
				m_xStdAnalyPro.Filter(kernel,3,7,0);
			}
			break;
		case ImgAnaly_LowStrain:
			{
				nRet = 0;
				long kernel[]={1,1,1,1,1,1,1,1,1};
				m_xStdAnalyPro.Filter(kernel,3,9,0);
			}
			break;
		case ImgAnaly_MedianStrain:
			{
				nRet = 0;
				int *pnData = (int*)(pVoid);
				//m_xStdAnalyPro.Median( *pnData );
			}
			break;
		case ImgAnaly_WaveletTransform:
			{
				nRet = 0;
				//m_xStdAnalyPro.Contour();
			}
			break;
		case ImgAnaly_BinaryImage:
			{
				nRet = 0;
				UINT *pnData = (UINT*)(pVoid);

				m_xStdAnalyPro.FindArea( *pnData );
			}
			break;
		default:
			{
				return -1;
			}
			break;
		} 

        m_xStdAnalyPro.m_arAnalyType.push_back( dwAnalyType );

	} while (FALSE);

	return 0;
}

int xkImgAnalyBit16::GetImgBuffer(zkImgBitInfo **ppImgInfo)
{
	m_xStdBitInfo.dwImgDefine  = eXKImage_Define_Img16;
	m_xStdBitInfo.bAutoDelete  = FALSE;
	m_xStdBitInfo.pImageHeader = &(m_xStdAnalyPro.m_xBitInfo);
	m_xStdBitInfo.pImageData   = m_xStdAnalyPro.m_xBitInfo.pwImageData;

    *ppImgInfo = &m_xStdBitInfo;

	return 0;
}


//To be Checked image
int xkImgAnalyBit16::SetChkImgBuffer(zkImgBitInfo *pImgInfo)
{
	if( NULL == pImgInfo || NULL == pImgInfo->pImageHeader )
	{
		return -1;
	}

	
	m_xChkAnalyPro.SetImgBuffer(pImgInfo);

	return 0;
}
//
int xkImgAnalyBit16::ChkImgOperate(DWORD dwAnalyType,void *pVoid )
{
	return 0;
}


int xkImgAnalyBit16::ImgAnaly()
{
	return 0;
}


